import { ClientSceneManagerComponent } from "../../../../Model/Share/Module/Scene/ClientSceneManagerComponent";
import { ObjectSystemAttribute, FriendOf, ExpandOf } from "../../../../../Decorator/Decorator";
import { AwakeSystem } from "../../../../../Core/Module/EventSystem/IAwakeSystem";
import { DestroySystem } from "../../../../../Core/Module/EventSystem/IDestroySystem";
import { Entity } from "../../../../../Core/Module/Entity/Entity";
import { Scene } from "../../../../../Core/Module/Entity/Scene";

/**
 * 使用 Expand 扩展方法
 * 
 * 必须作出以下申明，才能调用对象的扩展方法
 */
declare module "../../../../../Core/Module/Entity/Entity" {

    interface Entity {

        ClientScene(): Scene;

    }

}

@ExpandOf(Entity)
export class ClientSceneHelper {

    private static ClientScene(entity: Entity): Scene {
        return ClientSceneManagerComponent.Instance.Get(entity.DomainZone());
    }

}

/**
 * 使用 Expand 扩展方法
 * 
 * 必须作出以下申明，才能调用对象的扩展方法
 */
declare module "../../../../Model/Share/Module/Scene/ClientSceneManagerComponent" {

    interface ClientSceneManagerComponent {
        Get(id: number): Scene;
        Remove(id: number): void;
    }

}

@ExpandOf(ClientSceneManagerComponent)
export class ClientSceneManagerComponentSystem {

    private static Get(self: ClientSceneManagerComponent, id: number): Scene {
        const scene = self.GetChild<Scene>(id);
        return scene;
    }

    private static Remove(self: ClientSceneManagerComponent, id: number): void {
        self.RemoveChild(id);
    }

}


@FriendOf(ClientSceneManagerComponent)
@ObjectSystemAttribute()
export class ClientSceneManagerComponentAwakeSystem extends AwakeSystem<ClientSceneManagerComponent> {

    Awake(self: ClientSceneManagerComponent): void {
        ClientSceneManagerComponent.Instance = self;
    }

}

@FriendOf(ClientSceneManagerComponent)
@ObjectSystemAttribute()
export class ClientSceneManagerComponentDestroySystem extends DestroySystem<ClientSceneManagerComponent> {

    Destroy(self: ClientSceneManagerComponent): void {
        ClientSceneManagerComponent.Instance = null;
    }

}